#!/run/current-system/profile/bin/bash

if [ $# -ne 3 ] ; then
    echo "REQUIRED ARGS: dump conf tidy-file"
    exit
fi

dump="$1"
conf="$2"
tidyfile="$3"

if [ -L "$tidyfile" ] ; then
    hash="$(basename `readlink -f "$tidyfile"`)"
    
    echo "$hash$tidyfile" >> "$conf"
else
    hash=$(sha256sum "$tidyfile" | awk '{print $1;}')

    echo "$hash$tidyfile" >> "$conf"
    mv "$tidyfile" "$dump/$hash"
    ln -s `pwd`"/$dump/$hash" "$tidyfile"
    
    echo "NOTE: stashed $tidyfile to $hash"
fi
